<template>
  <div>
    品牌管理
    <el-table :data="attrList" border style="width: 100%">
      <el-table-column prop="type" width="50"> </el-table-column>
      <el-table-column prop="id" label="编号" width="70"> </el-table-column>
      <el-table-column prop="name" label="品牌名称" width="180">
      </el-table-column>
      <el-table-column prop="first_letter" label="品牌首字母" width="140">
      </el-table-column>
      <el-table-column prop="sort" label="排序" width="90"> </el-table-column>
      <el-table-column prop="factory_status" label="品牌制造商" width="100">
        <el-switch
          v-model="value"
          active-color="#13ce66"
          inactive-color="#ff4949"
        >
        </el-switch>
      </el-table-column>
      <el-table-column prop="factory_status" label="品牌是否显示" width="100">
        <el-switch
          v-model="value"
          active-color="#13ce66"
          inactive-color="#ff4949"
        >
        </el-switch>
      </el-table-column>
      <el-table-column label="相关" width="90"> </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button @click="handleClick(scope.row)" type="primary" size="small"
            >编辑</el-button
          >
          <el-button type="error" size="small">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="listQuery.pageNum"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="listQuery.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>
  </div>
</template>

<script>
//引入 商品类型的  获取数据的 函数
import { fetchProductAttrBrand } from "@/api/product.js";
export default {
  name: "brand",
  data: function () {
    return {
      attrList: [],
      value: true,
      listQuery: {
        pageSize: 10,
        pageNum: 1, //默认当前页是第一页
      },
      total: 0,
    };
  },
  created() {
    //获取数据
    fetchProductAttrBrand().then((res) => {
      console.log(res);
      this.attrList = res.data;
    });
    this.getProductAttrBrand();
  },
  methods: {
    //获取列表数据
    getProductAttrBrand() {
      fetchProductAttrBrand(this.listQuery).then((res) => {
        console.log(res);
        this.attrList = res.data;
        this.total = res.total;
      });
    },
    handleSizeChange(val) {
      console.log("修改页面条数的函数运行了", val);
      this.listQuery.pageSize = val;
      this.listQuery.pageNum = 1;
      //获取数据
      this.getProductAttrBrand();
    },
    handleCurrentChange(val) {
      console.log("修改当前页的页码的函数运行了", val);
      //将页码信息 保存到  listQuery
      this.listQuery.pageNum = val;
      //再次获取数据
      this.getProductAttrBrand();
    },
  },
};
</script>

<style>
</style>
